import { request } from '@/utils/api'

// 图片数据
interface ImageData {
  id: number
  url: string
  width: number
  height: number
  coordinate:DataItem[]
}
interface Coordinate {
  x: number
  y: number
}

// 数据项结构
interface DataItem {
  shapeIndex: number
  pdf_image_id: number
  text: string
  audio: string
  points: Coordinate[]
}

// 分页信息
interface PageInfo {
  current_page: number
  total_page: number
}

// API 响应结构
export interface PdfImagesResponse {
  data: ImageData[]
  page: PageInfo
}

interface ApiResponse<T> {
  data: T
  status: number
}

// 从 API 获取 PDF 图像列表
export async function getPdfImages(pdfId: number, page: number = 1): Promise<ApiResponse<PdfImagesResponse>> {
  try {
    const response = await request<PdfImagesResponse>({
      url: `/pdf/${pdfId}`,
      method: 'get',
      params: { page }
    });

    if (response.status >= 200 && response.status < 300) {
      return {
        data: response.data,
        status: response.status
      };
    } else {
      throw new Error(`API 请求失败，状态码: ${response.status}`);
    }
  } catch (error) {
    console.error('获取 PDF 图像列表时出错:', error);
    throw new Error(`获取 PDF 图像列表失败: ${(error as Error).message}`);
  }
}
